#!/usr/bin/python
# -*- coding: utf-8 -*-

# ------------------------------------------------------------
## インポート
# Python
import traceback

# ESiPC
from esipc import ESiPCProperty

# Mikan
from mikan.viewlet import *

# ------------------------------------------------------------
## Mikan メニュー アイテム クラス
#
class MikanJQMHeaderButtonItem(object):

	def set_href(self, value):
		self.FHref = value

	def get_href(self):
		return self.FHref

	def set_text(self, value):
		self.FText = value

	def get_text(self):
		return self.FText

	def set_css(self, value):
		self.FCss = value

	def get_css(self):
		return self.FCss

	def set_external(self, value):
		self.FExternal = value

	def get_external(self):
		return self.FExternal

	def set_iconpos(self, value):
		self.FIconpos = value

	def get_iconpos(self):
		return self.FIconpos

	def set_icon(self, value):
		self.FIcon = value

	def get_icon(self):
		return self.FIcon

	def set_transition(self, value):
		self.FTransition = value

	def get_transition(self):
		return self.FTransition

	def __init__(self, href, text, css=None, external=True, iconpos="text", icon=None, transition="slide"):
		super(MikanJQMHeaderButtonItem, self).__init__()

		self.FHref = href
		self.FText = text
		self.FCss = css
		self.FExternal = external
		self.FIconpos = iconpos
		self.FIcon = icon
		self.FTransition = transition

	# ----------------------------------------------------
	## Property
	icon = ESiPCProperty(get_icon, set_icon, None)
	transition = ESiPCProperty(get_transition, set_transition, None)
	icon = ESiPCProperty(get_icon, set_icon, None)
	iconpos = ESiPCProperty(get_iconpos, set_iconpos, None)
	external = ESiPCProperty(get_external, set_external, None)
	css = ESiPCProperty(get_css, set_css, None)
	text = ESiPCProperty(get_text, set_text, None)
	href = ESiPCProperty(get_href, set_href, None)

# ------------------------------------------------------------
## Mikan メニューバー ビューレットクラス
#
class MikanJQMMultiPagesViewlet(MikanViewlet):

	def get_element(self):
		return self.parent.element

	def __init__(self, parent):
		super(MikanJQMMultiPagesViewlet, self).__init__(parent)

	def perform(self):
		return super(MikanJQMMultiPagesViewlet, self).perform()

# ------------------------------------------------------------
## Mikan メニューバー ビューレットクラス
#
class MikanJQMPageViewlet(MikanDivViewlet):

	def get_title(self):
		return self.FTitle

	def get_header(self):
		return self.FHeader

	def get_content(self):
		return self.FContent

	def get_footer(self):
		return self.FFooter

	def __init__(self, parent, id, title, css="type-home", theme="a"):
		super(MikanJQMPageViewlet, self).__init__(parent)

		self.id = id
		self.FTitle = title
		self.clazz = css
		self.FDataTheme = theme

		self.FHeader = MikanJQMPageHeaderViewlet(self, title)
		self.FContent = MikanJQMContentViewlet(self)
		self.FFooter = MikanJQMPageFooterViewlet(self)

	def perform(self):
		if super(MikanJQMPageViewlet, self).perform() == False:
			return False

		self.element.setAttribute("data-role", "page")

		if 	self.FDataTheme != None:
			self.element.setAttribute("data-theme", self.FDataTheme)
		if 	self.FTitle != None:
			self.element.setAttribute("data-title", self.FTitle + " - " + self.request.config.get("site", "title"))

		return True

	# ----------------------------------------------------
	## Property
	title = ESiPCProperty(get_title, None, None)
	header = ESiPCProperty(get_header, None, None)
	footer = ESiPCProperty(get_footer, None, None)
	content = ESiPCProperty(get_content, None, None)

# ------------------------------------------------------------
## Mikan メニューバー ビューレットクラス
#
class MikanJQMPageTabletViewlet(MikanJQMPageViewlet):

	def get_submenu(self):
		return self.FSubMenu

	def get_primary_content(self):
		return self.FPrimaryContent

	def get_secondary_content(self):
		return self.FSecondaryContent

	def __init__(self, parent, id, title, css="type-interior", theme="a"):
		super(MikanJQMPageTabletViewlet, self).__init__(parent, id, title, css, theme)

		self.FPrimaryContent = MikanJQMPrimaryContentViewlet(self.content)
		self.FSecondaryContent = MikanJQMSecondaryContentViewlet(self.content)

		self.FSubMenu = MikanJQMListViewViewlet(self.FSecondaryContent)

	def perform(self):
		if super(MikanJQMPageTabletViewlet, self).perform() == False:
			return False

		return True

	# ----------------------------------------------------
	## Property
	submenu = ESiPCProperty(get_submenu, None, None)
	secondarycontent = ESiPCProperty(get_secondary_content, None, None)
	primarycontent = ESiPCProperty(get_primary_content, None, None)

# ------------------------------------------------------------
## Mikan メニューバー ビューレットクラス
#
class MikanJQMPageHeaderViewlet(MikanDivViewlet):

	def set_title(self, value):
		self.FTitle = value

	def get_title(self):
		return self.FTitle

	def get_icons(self):
		return self.FIcons

	def __init__(self, parent, title):
		super(MikanJQMPageHeaderViewlet, self).__init__(parent)

		self.sortkey = -1000
		self.FTitle = title

		MikanH1Viewlet(self, self.FTitle)

		self.FIcons = MikanJQMIconsViewlet(self)
#		MikanJQMIconViewlet(self.FIcons, self.request.wsgiurl, u"ホーム", icon=None, external=True, iconpos="text")
#		MikanJQMIconViewlet(self.FIcons, "#home", u"ページトップ", icon=None, iconpos="text")

	def perform(self):

		if super(MikanJQMPageHeaderViewlet, self).perform() == False:
			return False

		self.element.setAttribute("data-role", "header")

		return True

	# ----------------------------------------------------
	## Property
	icons = ESiPCProperty(get_icons, None, None)
	title = ESiPCProperty(get_title, set_title, None)

# ------------------------------------------------------------
## Mikan メニューバー ビューレットクラス
#
class MikanJQMPageFooterViewlet(MikanDivViewlet):

	def __init__(self, parent):
		super(MikanJQMPageFooterViewlet, self).__init__(parent)
		self.sortkey = 1000

	def perform(self):
		if super(MikanJQMPageFooterViewlet, self).perform() == False:
			return False

		self.element.setAttribute("data-role", "footer")

		return True

# ------------------------------------------------------------
## Mikan メニューバー ビューレットクラス
#
class MikanJQMContentViewlet(MikanDivViewlet):

	def __init__(self, parent):
		super(MikanJQMContentViewlet, self).__init__(parent)
		self.sortkey = 100

	def perform(self):
		if super(MikanJQMContentViewlet, self).perform() == False:
			return False

		self.element.setAttribute("data-role", "content")

		return True

# ------------------------------------------------------------
## Mikan メニューバー ビューレットクラス
#
class MikanJQMPrimaryContentViewlet(MikanDivViewlet):

	def __init__(self, parent):
		super(MikanJQMPrimaryContentViewlet, self).__init__(parent)

		self.clazz = "content-primary main-content"
		self.sortkey = 200

	def perform(self):
		if super(MikanJQMPrimaryContentViewlet, self).perform() == False:
			return False

		return True

# ------------------------------------------------------------
## Mikan メニューバー ビューレットクラス
#
class MikanJQMSecondaryContentViewlet(MikanDivViewlet):

	def is_enable(self):
		return self.FEnable

	def __init__(self, parent):
		super(MikanJQMSecondaryContentViewlet, self).__init__(parent)

		self.clazz = "content-secondary aside-content"
		self.sortkey = 100
		self.FEnable = True

	def perform(self):
		if self.isenable:
			if super(MikanJQMSecondaryContentViewlet, self).perform() == False:
				return False

		return True

	# ----------------------------------------------------
	## Property
	isenable = ESiPCProperty(is_enable, None, None)


# ------------------------------------------------------------
## Mikan メニューバー ビューレットクラス
#
class MikanJQMIconsViewlet(MikanDivViewlet):

	def __init__(self, parent):
		super(MikanJQMIconsViewlet, self).__init__(parent)

	def perform(self):
		if super(MikanJQMIconsViewlet, self).perform() == False:
			return False

		self.element.setAttribute("data-role", "controlgroup")
		self.element.setAttribute("data-type", "horizontal")

		return True

# ------------------------------------------------------------
## Mikan メニューバー ビューレットクラス
#
class MikanJQMAViewlet(MikanAViewlet):

	def __init__(self, parent, href, text, external=False, transition="slide"):
		super(MikanJQMAViewlet, self).__init__(parent, href, None)

		self.FExternal = external
		self.FValue = text
		self.FTransition = transition

	def perform(self):
		if super(MikanJQMAViewlet, self).perform() == False:
			return False

		if self.FTransition != None:
			self.element.setAttribute("data-transition", self.FTransition)
		if self.FExternal == True:
			self.element.setAttribute("rel", "external")
		return True

# ------------------------------------------------------------
## Mikan メニューバー ビューレットクラス
#
class MikanJQMLiViewlet(MikanLiViewlet):

	def __init__(self, parent, role, value):
		super(MikanJQMLiViewlet, self).__init__(parent, value)

		self.FRole = role

	def perform(self):
		if super(MikanJQMLiViewlet, self).perform() == False:
			return False

		if self.FRole != None:
			self.element.setAttribute("data-role", self.FRole)

		return True

# ------------------------------------------------------------
## Mikan メニューバー ビューレットクラス
#
class MikanJQMIconViewlet(MikanJQMAViewlet):

	def __init__(self, parent, href, text, css=None, external=False, iconpos="notext", icon="home", transition="slide"):
		super(MikanJQMIconViewlet, self).__init__(parent, href, text, external, transition)

		self.clazz = css
		self.FIcon = icon
		self.FIconpos = iconpos

	def perform(self):
		if super(MikanJQMIconViewlet, self).perform() == False:
			return False

		if self.FIcon != None:
			self.element.setAttribute("data-icon", self.FIcon)
		if self.FIconpos != None:
			self.element.setAttribute("data-iconpos", self.FIconpos)
		self.element.setAttribute("data-role", "button")

		return True

# ------------------------------------------------------------
## Mikan メニューバー ビューレットクラス
#
class MikanJQMListViewViewlet(MikanUlViewlet):

	def get_theme(self):
		return self.FTheme

	def __init__(self, parent, theme=None):
		super(MikanJQMListViewViewlet, self).__init__(parent)

		self.FTheme = theme

	def perform(self):
		if super(MikanJQMListViewViewlet, self).perform() == False:
			return False

		if (self.FTheme != None):
			self.element.setAttribute("data-dividertheme", self.FTheme)
		self.element.setAttribute("data-role", "listview")
		self.element.setAttribute("data-inset", "true")
		self.element.setAttribute("data-inline", "true")

		return True

	# ----------------------------------------------------
	## Property
	theme = ESiPCProperty(get_theme, None, None)

# ------------------------------------------------------------
## Mikan メニューバー ビューレットクラス
#
class MikanJQMSXBItemViewlet(MikanJQMPageTabletViewlet):

	def __init__(self, parent):
		super(MikanJQMSXBItemViewlet, self).__init__(parent)

	def perform(self):
		if super(MikanJQMSXBItemViewlet, self).perform() == False:
			return False

		return True
